
<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.users.UserGroup,
                 com.scalar.chiptrack.commons.SessionKeys,
                  com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants"%>

<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<chiptrack:checkLogon sourcePage="/jsp/admin/admin.jsp"/>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<%
try
    {%>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>

<SCRIPT language="javascript">

//----- This function is used to check the Job Names,handler and Frequency values.-------
function checkJobNames()
{
	var formName = document.systemJobSetupForm;
	var pa = document.getElementById( "message" );
	var noOfJobs = ( parseInt( formName.newcount.value ) + parseInt( formName.newbgcount.value ) );
	if( parseInt( noOfJobs ) > 1 )
	{
		for( var i = 0; i < parseInt( noOfJobs ); i++ )
		{
			var jobName		= formName.jobName[i].value;
			var handlerName	= formName.handler[i].value;

			jobName	= trim(jobName);
			formName.jobName[i].value = jobName;

			if( ( jobName == '' ) && ( handlerName != '' ) )
			{
				pa.innerHTML = "<li> Please Enter Job Name at Line No " + parseInt(i + 1);
				return false;
			}

			if( jobName != '' )
			{
				if(AlphaNumHyphen(jobName,'','Y') == false)
				{
					pa.innerHTML = "<li> Please Enter Valid Job Name at Line No " + parseInt(i + 1);
					return false;
				}
				
				if(trim(handlerName) == '')
				{
					pa.innerHTML = "<li> Please Enter Handler value at Line No  " + parseInt(i + 1);
					return false;
				}
			 
				for(var j=(parseInt(i)+1);j<parseInt(noOfJobs);j++ )
				{
					if(i!=j)
					{
						if(jobName.toLowerCase() == trim(formName.jobName[j].value).toLowerCase())
						{
							pa.innerHTML = "<li> Same Job Names are not allowed here.  Please change... ";
							return false;
						}
					}
				}
			}
		}
	}
	else if( parseInt( noOfJobs ) == 1 )
	{
		var jobName		= formName.jobName.value;
		var handlerName	= formName.handler.value;

		jobName	= trim(jobName);
		formName.jobName.value = jobName;

		if( ( jobName == '' ) && ( handlerName != '' ) )
		{
			pa.innerHTML = "<li> Please Enter Job Name at Line No 1" ;
			return false;
		}

		if( jobName != '' )
		{
			if( AlphaNumHyphen( jobName, '', 'Y' ) == false )
			{
				pa.innerHTML = "<li> Please Enter Valid Job Name at Line No 1" ;
				return false;
			}
				
			if( trim( handlerName ) == '' )
			{
				pa.innerHTML = "<li> Please Enter Handler value at Line No 1";
				return false;
			}
		}
	}
	return true;
}


function submitForm()
{
	formName = document.systemJobSetupForm;
	if( checkJobNames() == true )
	{
		  formName.action.value="save";
		  formName.submit();
	}
}


function changeStatus(lineno)
{
	formName = document.systemJobSetupForm;
    var noOfRows = (parseInt(formName.newcount.value) + parseInt(formName.newbgcount.value));
	if( noOfRows == 1 )
	{
		var jobName = formName.jobName.value;
        var jobId = formName.id.value;
        var status = formName.disabled.value;
	}
    else
    {
		var jobName = formName.jobName[lineno].value;
        var jobId = formName.id[lineno].value;
        var status = formName.disabled[lineno].value;
	}

    formName.delid.value = jobId;
    formName.delname.value = jobName;
    formName.selectedstatus.value = status;

    formName.action.value = "changestatus";
    formName.submit();
}

function addNewRow()
{
	formName = document.systemJobSetupForm;
    var count = formName.newcount.value;
    var newbgcount = formName.newbgcount.value;

    var htmltext = ' <div> <table width="100%" align="center" border="0" cellpadding="0" cellspacing="1"> <tr>';
    htmltext = htmltext + '<td align="left" width="20%" bgcolor="#DEE1E2"><font class="NArialL">';
    htmltext = htmltext + '<input type ="text" name="jobName" size="25" Class="txfield" maxlength="50"/></font></td>';
    htmltext = htmltext + '<td align="left" width="50%" bgcolor="#DEE1E2"><font class="NArialL">';
    htmltext = htmltext + '<input type ="hidden" name="id" value=""/>';
    htmltext = htmltext + '<input type ="text" name="handler" Class="txfield"';
    htmltext = htmltext + 'size="70" align="left" maxlength="200"/></font></td>';
    htmltext = htmltext + '<input type ="hidden" name="startTime" value=""/>';
    htmltext = htmltext + '<td bgcolor="#DEE1E2" width="15%"><font class="NArialL">';
    htmltext = htmltext + '<td bgcolor="#DEE1E2" width="15%"> ';
    htmltext = htmltext + '&nbsp;</td>';

    htmltext = htmltext + '</tr></table></div>';

    var pa=document.getElementById("font1");
    pa.insertAdjacentHTML('BeforeEnd',htmltext);
    /*var  noofrows = parseInt(newbgcount)+parseInt(count);
    if( noofrows > 1)
	{
		formName.jobName[noofrows].focus();
	}
	else
	{
		formName.jobName.focus();
	}*/
    count++;
    formName.newcount.value = count;
}

function reset()
{
    document.systemJobSetupForm.reset();
}

function scheduleJob( lineno )
{
	formName = document.systemJobSetupForm;
	var noOfRows = (parseInt(formName.newcount.value) + parseInt(formName.newbgcount.value));

	if(noOfRows == 1)
	{
	   var jobId = formName.id.value;
	   var jobName = formName.jobName.value;
	}
	else
	{
	   var jobId = formName.id[lineno].value;
	   var jobName = formName.jobName[lineno].value;
	}
	formName.delid.value = jobId;  //hidden variable "delid", here used for Scheduling the Job.
	formName.delname.value = jobName;
	formName.action.value = "scheduleJob";
	formName.submit();
}
function exportToFile( )
    {
        formName = document.systemJobSetupForm;
        var url = '<%=chipTracContext%>/systemJobSetup.do?action=exporttoexcel';
        newWindow = window.open ( url,'printerFriendlyPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=450,height=150,resizable=yes');
    }

</script>

<%
    String action = ((request.getParameter("action")!=null)?(request.getParameter("action")):"").trim();
    String jobId = null;
    String jobName = null;
%>
<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@ include file="/jsp/admin/admin_menu.jsp" %>
<!-- end of the side navigations -->
</TD>

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
 <TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>

<center><font class="NArialW">System Job Setup</FONT></center><br>

<html:form name="systemJobSetupForm" method="post" action="/systemJobSetup" type="com.scalar.chiptrack.users.forms.SystemJobSetupForm">
    <table width="100%" align=center border="0" cellpadding='0' cellspacing=2>

        <tr><td colspan=5><chiptrack:info styleClass="NArialL" /></td></tr>
        <tr><td colspan=5><chiptrack:errors styleClass="NArialL" />
          <Strong>
            <font face="Verdana" size="-5" align="center" color="#ff0000" id="message"></font>
          </strong>
        </td></tr>
        <logic:equal name="showMessage" value="TRUE">
            <tr><td colspan=2 align='left' class='NArialS'>
            <font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b>
            </font></td></tr>
        </logic:equal>

        <tr>
            <td colspan="5" valign="top" align = "left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a class="NArialL" href="javascript:exportToFile()" onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
            </td>
        </tr>
        <tr><td colspan='5'><IMG height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>
        <tr bgcolor="#993333">
            <td  align="center" width ="20%" class="NArialL"><font color="#FFFFFF">Job Name</font></td>
            <td  align="center" width="40%" class="NArialL"><font color="#FFFFFF">Handler</font></td>
            <td  align="center" width="10%" class="NArialL" nowrap><font color="#FFFFFF">Sch.Time</font></td>
            <td  align="center" width="15%" class="NArialL"><font color="#FFFFFF">Actions</font></td>
            <td  align="center" width="15%" class="NArialL"><font color="#FFFFFF">Schedule</font></td>
        </tr>

        <tr><td colspan='5'><IMG height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>

        <% int bgcount = 0;%>
        <logic:iterate id="Job" name="jobsList">
        <% bgcount = bgcount + 1; %>
	<tr>
          <html:hidden name="Job" property="id"/>
          <html:hidden name="Job" property="startTime"/>
          <html:hidden name="Job" property="jobName"/>
          <html:hidden name="Job" property ="disabled"/>

      <td align="center" bgcolor='#DEE1E2'><font class="NArialL"><input type=text disabled="disabled" name="jobNameDis" Class="txfield" value="<bean:write name="Job" property="jobName" />"  size="25">
      </font></td>
      <td align="center" bgcolor='#DEE1E2'><font class="NArialL"><html:text name="Job" property="handler" styleClass="txfield" disabled="false" size="70" maxlength="200"/></font></td>
      <td align="center" bgcolor='#DEE1E2'><font class="NArialL">
        <logic:equal name = "Job" property = "disabled" value = "false">

            <logic:equal name = "Job" property = "amPm" value = "0">
            <bean:write name="Job" property="scheduleTime" />:<bean:write name="Job" property="scheduleMinute" />&nbsp;AM
            </logic:equal>
            <logic:equal name = "Job" property = "amPm" value = "1">
                <bean:write name="Job" property="scheduleTime" />:<bean:write name="Job" property="scheduleMinute" />&nbsp;PM
            </logic:equal>
        </logic:equal>
      </td>
      <td align="center" bgcolor="#DEE1E2">
      <font class="NArialL">
      <chiptrack:restrictedLink functionality='<%=Functionality.SYSTEM_JOB_SETUP%>' action='<%=User.USER_ACTION_DELETE%>'
      href='<%="javascript:changeStatus("+(bgcount -1)+")"%>' onmouseover="window.status='Click to Change Job Status';return true" onmouseout="window.status='';return true">
      <logic:equal name = "Job" property = "disabled" value = "false">Disable</logic:equal>
      <logic:equal name = "Job" property = "disabled" value = "true"><font color="red">Activate</font></logic:equal>
      </chiptrack:restrictedLink>
      </font>
      </td>
      <td align="center" bgcolor="#DEE1E2">
      <font class="NArialL">
      <chiptrack:restrictedLink functionality='<%=Functionality.SYSTEM_JOB_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>'
      href='<%="javascript:scheduleJob("+(bgcount -1)+")"%>' onmouseover="window.status='Click for Scheduling Job';return true" onmouseout="window.status='';return true">
      Schedule
      </chiptrack:restrictedLink>
      </font>

	</tr>
        </logic:iterate>

        <tr><td colspan='5'  align="center"><FONT id="font1"></FONT></TD></TR>


        <tr><td colspan="5"><img src='<%=chipTracContext%>/jsp/includes/images/spacer.gif' height=20></td></tr>
        <tr><td colspan="5" align=center>
            <chiptrack:restrictedLink functionality='<%=Functionality.SYSTEM_JOB_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:submitForm();' onmouseover="window.status='Click to Save System Jobs';return true" onmouseout="window.status='';return true">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title='Click here to Save System Jobs '/>
            </chiptrack:restrictedLink>
        <%--<a href="javascript:submitForm();"><img src='<%=chipTracContext%>/jsp/includes/images/save.gif' border=0 onmouseover="window.status='Click to Save System Jobs';return true" onmouseout="window.status='';return true" title="Click here to Save System Jobs "></a>--%>

            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:reset();"><img src='<%=chipTracContext%>/jsp/includes/images/reset.gif' border=0 onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <chiptrack:restrictedLink functionality='<%=Functionality.SYSTEM_JOB_SETUP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:addNewRow();' onmouseover="window.status='Click to Add more Jobs';return true" onmouseout="window.status='';return true">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" title='Click here to Add more Jobs'/>
            </chiptrack:restrictedLink>
           <%-- <a href="javascript:addNewRow();"><img src='<%=chipTracContext%>/jsp/includes/images/addmore.gif' border=0 onmouseover="window.status='Click to Add more Jobs';return true" onmouseout="window.status='';return true" title="Click here to Add more Jobs "></a>--%>
          </td></tr>
</table>
<!-- This Hidden field is used to get the users action..  -->
<input type="hidden" name="action" value="">
<!-- This Hidden field is used to get the users action..  -->

<!-- This Hidden field is used to get the Job Id to be deleted ..  -->
<input type="hidden" name="delid" value="">
<!-- This Hidden field is used to get the Job Id to be deleted ..  -->

<!-- This Hidden field is used to get the Job Name to be deleted ..  -->
<input type="hidden" name="delname" value="">
<!-- This Hidden field is used to get the Job Name to be deleted ..  -->

<!-- This Hidden field is used to get the count of rows whic are added dynamically ..  -->
<input type="hidden" name="newcount" value="0">
<!-- This Hidden field is used to get the count of rows whic are added dynamically ..  -->

<!-- This Hidden field is used to get the Count of rows in the iterating loop ..  -->
<input type="hidden" name="newbgcount" value="<%=bgcount%>">
<!-- This Hidden field is used to get the Count of rows in the iterating loop ..  -->

<!-- This Hidden field is used to get the Status flag ..  -->
<input type="hidden" name="selectedstatus" value="">
<!-- This Hidden field is used to get the Status flag ..  -->
 </html:form>

<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>
<%
    }
    catch (Exception e)
    {e.printStackTrace();}
%>